<?php
/**
 * KumbiaPHP web & app Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://wiki.kumbiaphp.com/Licencia
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@kumbiaphp.com so we can send you a copy immediately.
 *
 * Paginador "classic" para aplicaciones
 *
 * Parametros del paginador:
 *   page: objeto obtenido al invocar al paginador
 *   show: numero de paginas que se mostraran en el paginador
 *   url: url para la accion que efectua la paginacion, por defecto "module/controller/page/"
 *        y se envia por parametro el numero de pagina
 * 
 * @category   Kumbia
 * @package    Partials 
 * @copyright  Copyright (c) 2005-2009 Kumbia Team (http://www.kumbiaphp.com)
 * @license    http://wiki.kumbiaphp.com/Licencia     New BSD License
 */

//if(!isset($url)) {
 //   extract(Router::get());

    $array_url	=	Router::get('parameters');
    $id = '';
    
    //$url	= substr($url,0,-1);
    //$url = "$controller/page";
//    if($module) {
//        $url = "$module/$url";
//    }
//}
if(!isset($show)) {
    $show = 10;
}
$half = (int)($show/2);
    
/**
 * Calculando el inicio de paginador centrado
 **/
if ($page->current <= $half) {
    $start = 1;
} elseif (($page->total - $page->current)<$half) {
    $start = $page->total - $show + 1;
} else {
    $start = $page->current - $half;
}
?>

<div class="paginator">
    <?php 
    	if($page->prev){ ?>
		<a href='<?php echo PUBLIC_PATH . "$url/1/$id" ?>'><img src="<?php echo PUBLIC_PATH . 'img/datagrid/first.gif' ?>" class='first' alt='Primero'></a>
		<a href='<?php echo PUBLIC_PATH . "$url/$page->prev/$id" ?>'><img src="<?php echo PUBLIC_PATH . 'img/datagrid/prev.gif' ?>" class='prev' alt='Anterior'></a>
<?php	}else{?>
    		<img src="<?php echo PUBLIC_PATH . 'img/datagrid/first.d.gif' ?>" class='first' alt='Primero'>
		<img src="<?php echo PUBLIC_PATH . 'img/datagrid/prev.d.gif' ?>" class='prev' alt='Anterior'>
<?php  	} ?>

    <?php
    	$option_value	=	'';
    	for($i=1; $i<=$page->total; $i++):
    		if($page->current == $i){ $selected = 'selected="selected"'; }else{ $selected = ''; }
    		$option_value	.=	'<option value ="' . $i . '" ' . $selected . '>' . $i  .'</option>';
    	endfor;
    ?>
    	P&aacute;gina &nbsp;
    	<select onchange="cambiar(this);">
       	<?php	echo $option_value; ?>
    	</select>
<?php
		echo '&nbsp; de ' . $page->total . '&nbsp;&nbsp;';
    	if($page->next){ ?>
		<a href='<?php echo PUBLIC_PATH . "$url/$page->next/$id" ?>'><img src="<?php echo PUBLIC_PATH . 'img/datagrid/next.gif' ?>" class='next' alt='Siguiente'></a>
		<a href='<?php echo PUBLIC_PATH . "$url/$page->total/$id" ?>'><img src="<?php echo PUBLIC_PATH . 'img/datagrid/last.gif' ?>" class='last' alt='Ultimo'></a>
<?php	}else{ ?>
    		<img src="<?php echo PUBLIC_PATH . 'img/datagrid/next.d.gif' ?>" class='next' alt='Siguiente'>
		<img src="<?php echo PUBLIC_PATH . 'img/datagrid/last.d.gif' ?>" class='last' alt='Ultimo'>
<?php   } ?>
    Total de Registros: <strong><?php echo $page->count; ?></strong>
</div>
<script>
function cambiar(obj){
	window.location.href=	"<?php echo PUBLIC_PATH  . $url . '/'  ?>" + obj.options[obj.selectedIndex].value + "/" + "<?php echo $id; ?>";
}
</script>